<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:text name="topic.list.title"/></title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
<div id="wrapper">
<div id="main_box">
	<div class="curmb"><s:text name="your.site.position"/>:<a href="${ctx}/main.action"><s:text name="homepage"/></a><span>></span><s:text name="topic.title"/></div>
	<div class="listtit" id="listtit"><p><span><strong><s:text name="topic.list.title"/></strong></span></p></div>
	<s:form action="topic-list" id="search_form">
	<s:hidden name="adminName" id="adminName"></s:hidden>
	<s:hidden name="topicId" id="topicId"></s:hidden>
	<div class="searchbox">
		<table class="searchTable">
			<tbody id="searchTable">
				<tr>
					<td><label for="qry_topicName"><s:text name="topic.topicName"/>: </label></td>
					<td><s:textfield name="topic.topicName"  cssClass="txtsearch" id="qry_topicName" maxlength="30"   /></td>
					
					<td class="text"><s:text name="topic.isEnable"/></td>
					<td>
						<s:if test="dicIsEnable!=null">
							<s:select name="topic.isEnebleForPage" list="dicIsEnable" listKey="dictionaryKey" listValue="dictionaryValue" value="topic.isEnable" cssClass="selectClass" headerKey="" headerValue="请选择"/>
						</s:if>
					</td>
					<td><input type="button" value="<s:text name="query"/>" class="btnsearch" id="search_btn"/><span id="extend">高级查询</span></td>
				</tr>
				<tr class="extend" style="display: none">
					<td><label for="qry_createTime"><s:text name="topic.createTime"/>: </label></td>
					<td>
					<input name="topic.createTime" class="Wdate" readonly="true" id="topic_beginTime" value="<s:date name="topic.createTime" format="yyyy-MM-dd"/>"
							onFocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',maxDate:$('#topic_endTime').val()})" type="text"/>
					</td>
					<td><label for="qry_endTime"><s:text name="topic.endTime"/>: </label></td>
					<td>
					<input name="topic.endTime" class="Wdate" readonly="true" id="topic_endTime"  value="<s:date name="topic.endTime" format="yyyy-MM-dd"/>"
							onFocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate:$('#topic_beginTime').val()})" type="text"/>
					</td>
				</tr>
				<tr class="extend" style="display: none">
					<td><label for="qry_keywords"><s:text name="topic.keywords"/>: </label></td>
					<td><s:textfield name="topic.keywords"  cssClass="txtsearch" id="qry_keywords"/></td>
					<td><label for="qry_topicStatus"><s:text name="topic.topicStatus"/>: </label></td>
					<td><s:if test="dicTopicStatus!=null">
						<s:select name="topic.topicStatus" list="dicTopicStatus" listKey="dictionaryKey" listValue="dictionaryValue" value="topic.topicStatus" cssClass="selectClass" headerKey="" headerValue="请选择"/>
					</s:if></td>
				</tr>
			</tbody>
		</table>
		<div class="clear"></div>
	</div>
	<div class="listoperate">
		<span class="cssa">
		<s:if test="%{authLicenceLikeSite('2_2_3')}">
			<input id="top_new_btn" type="button" value="<s:text name="new"/>" class="btnadd"/>
		</s:if>
		<s:else>
			<input id="top_new_btn" disabled="disabled" type="button" value="<s:text name="new"/>" class="btnadd"/>
		</s:else>
		</span>
		<span>
			<input type="button" value="<s:text name="anti-selection"/>" class="btnlist2" id="top_anti_btn"/>
				<input type="button" value="<s:text name="delete"/>" class="btnlist2" id="top_del_btn"/>
				<input type="button" value="<s:text name="enable"/>" class="btnlist2" id="top_enable_btn"/>
				<input type="button" value="<s:text name="disable"/>" class="btnlist2" id="top_disable_btn"/>
				<input type="button" value="<s:text name="audit"/>" class="btnlist2" id="top_audit_btn"/>
				<input type="button" value="<s:text name="noAudit"/>" class="btnlist4" id="top_noAudit_btn"/>			
		</span>
	</div>
	<div class="listbox" id="listbox">
		<table class="listgrid" id="listbox">
			<tbody>
				<tr>
					<th><input type="checkbox" name="all" id="all_check"/></th>
					<th><s:text name="topic.topicName"/></th>
					<th><s:text name="topic.keywords"/></th>
					<th><s:text name="topic.topicStatus"/></th>
					<th><s:text name="topic.isEnable"/></th>
					<th><s:text name="topic.endTime"/></th>
					<th><s:text name="operate"/></th>
				</tr>
				<s:iterator value="page.result">
					<tr>
					<input type="hidden" value="<s:property value="keywords"/>" id="keywords">
					<td><input type="checkbox" name="key" value="<s:property value="topicId"/>"/></td>
					<s:if test="isAudit==1">
						<td align="left" class="sh_ready"><s:property value="topicName"/>&nbsp;</td>
					</s:if>
					<s:else>
						<td align="left" class="sh_noready"><s:property value="topicName"/>&nbsp;</td>
					</s:else>
					<td name="keywordsmanager"><s:property value="keywords"/>&nbsp;</td>
					<td><s:property value="%{getName(topicStatus,'TOPIC_STATUS')}"/>&nbsp;</td>
					<td>
						<s:if test="isEnable == true"><s:text name="yetEnable"/></s:if><s:else><span style="color:red;"><s:text name="yetDisable" /></span></s:else>&nbsp;
					</td>
					<td><s:property value="endTime"/>&nbsp;</td>				
					<td>
					<s:if test="%{authLicence('4_4_1',topicId)}">
						<a href="#this" onclick="goEdit('topic.topicId','<s:property value="topicId"/>')"><s:text name="edit"/></a><tt>|</tt>
					    <a href="#this" onclick="goDeltest('<s:property value="topicId"/>')"><s:text name="delete"/></a><tt>|</tt>
					    <a href="#this" onclick="disableOrEnable('<s:property value="topicId"/>',<s:if test="isEnable==1">1</s:if><s:else>2</s:else>);"><s:if test="isEnable==1"><s:text name="disable"/></s:if><s:else><s:text name="enable"/></s:else></a><tt>|</tt>
					    <a href="#this" onclick="authorSelect('<s:property value="topicId"/>','<s:property value="auditRealName"/>')" name="authorSet" id="<s:property value="topicId"/>"> <s:text name="authorSet"/></a><tt>|</tt>
						<a href="#this" onclick="goDynamicPreview('<s:property value="topicId"/>')"><s:text  name="dynamicPreview"/></a><tt>|</tt>
						<a href="#this" onclick="goStaticPreview('<s:property value="topicId"/>')"><s:text name="staticPreview"/></a><tt>|</tt>
					 </s:if> 
					 <s:else>
					 	<s:text name="edit"/><tt>|</tt>
					    <s:text name="delete"/><tt>|</tt>
					    <s:if test="isEnable==1"><s:text name="disable"/></s:if><s:else><s:text name="enable"/></s:else><tt>|</tt>
					    <s:if test="isAudit==1"><s:text name="noAudit"/></s:if><s:else><s:text name="audit"/></s:else><tt>|</tt>
					    <s:text name="authorSet"/><tt>|</tt>
					    <s:text  name="dynamicPreview"/><tt>|</tt>
						<s:text name="staticPreview"/><tt>|</tt>
					 </s:else>  
					 
					 <s:if test="%{authLicence('4_4_2',topicId)}">
					 	<a href="#this" onclick="goPublish('<s:property value="topicId"/>')"><s:text name="publish"/></a><tt>|</tt>
					 </s:if>
					 <s:else>
					 	<s:text name="publish"/><tt>|</tt>
					 </s:else>	   
					   
					  <s:if test="%{authLicence('4_4_4',topicId)}">
					  	<a href="#this" onclick="goAudit('<s:property value="topicId"/>')"><s:text name="审核"/></a><tt>|</tt>
					  </s:if>
					   <s:else>
					   	<s:text name="审核"/><tt>|</tt>
					   </s:else>
					 <s:if test="%{authLicence('4_4_3',topicId)}">
					    <a href="#this" onclick="goManage('<s:property value="topicId"/>')"><s:text name="manage"/></a>
					 </s:if>
					 <s:elseif test="%{authLicence('4_4_4',topicId)}">
					 	 <a href="#this" onclick="goManage('<s:property value="topicId"/>')"><s:text name="manage"/></a>
					 </s:elseif>
					 <s:elseif test="%{authLicence('4_4_2',topicId)}">
					 	 <a href="#this" onclick="goManage('<s:property value="topicId"/>')"><s:text name="manage"/></a>
					 </s:elseif>
					 <s:else>
					    <s:text name="manage"/>
					 </s:else>
					</td>
					</tr>
				</s:iterator>
			</tbody>
		</table>
	</div>
	<div class="listoperateb h60">
		
		<span class="fl">
			<input type="button" value="<s:text name="anti-selection"/>" class="btnlist2" id="bottom_anti_btn"/>
				<input type="button" value="<s:text name="enable"/>" class="btnlist2" id="bottom_enable_btn"/>
				<input type="button" value="<s:text name="disable"/>" class="btnlist2" id="bottom_disable_btn"/>
				<input type="button" value="<s:text name="audit"/>" class="btnlist2" id="bottom_audit_btn"/>
				<input type="button" value="<s:text name="noAudit"/>" class="btnlist4" id="bottom_noAudit_btn"/>
				
		</span>
		<div class="pager fr w550"><z:page numberNav="true" selectPageSize="true" input="true" id="ctrl"/></div>
		<div class="clear"></div>
	</div>
</div>
</div>
<div id="lightbox" class="lightbox">
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose" class="lightclose" /><strong>审核人设置</strong></span></p></div>
	<div class="lightmain">
		<div class="lightmaintit">请选择审核人</div>
		<div class="ilghtmainbox">
			<div id="authorSetDiv"></div>
		</div>
		<div class="lightbtnbox"><input type="button" value="确认" id="lightsubmit" class="btnlist2" onclick="authorSet()"/><input type="button" id="closebtn" value="关闭"  class="btnlist2" /></div>
	</div>
</div>
</s:form>
</body>
</html>
<script type="text/javascript">
	actionName = "topic";	
	confirmStr = "<s:text name="delete.confirm"/>";
	chiocenothing = "<s:text name="chiocenothing"/>";
	$(function(){
 		$("#top_new_btn").click(goNew);
 		$("#top_anti_btn").click(antiSelect);
 		$("#top_del_btn").click(goBatchDel);
 		$("#bottom_anti_btn").click(antiSelect);
		$("#search_btn").click(search);
		$("#all_check").click(selAll);
		$("#extend").click(extend);
		
		$("#top_enable_btn").click(batchEnable);
		$("#top_disable_btn").click(batchDisable);
		$("#top_audit_btn").click(batchAudit);
		$("#top_noAudit_btn").click(batchNoAudit);	
	
		
		$("#bottom_enable_btn").click(batchEnable);
		$("#bottom_disable_btn").click(batchDisable);
		$("#bottom_audit_btn").click(batchAudit);
		$("#bottom_noAudit_btn").click(batchNoAudit);	
	
		
		var arr = $$.g("#listbox a");
		for (var i = 0; i < arr.length; i ++){
			 if (arr[i].name == "authorSet"){
				 var id = arr[i].id;
				 $("#"+arr[i].id).bind("click",function(){
			 		$$.shade("#"+id+"","#lightclose,#closebtn,#lightsubmit","#lightbox");
				});
			 }
		}
		 
	
	});
	
	var maxLen = 12;
	$(document).ready(function(){
		$("td[name=keywordsmanager]").each(function(){
			if($(this).html().substr(0,$(this).html().length-6).length>=maxLen){
				$(this).attr("title",$(this).html().substr(0,$(this).html().length-6));
				$(this).html($(this).html().substr(0,maxLen)+"......");
			}
		});
	});
	
	//禁用/启用
	function disableOrEnable(id,dn){
		var myDate=new Date();
		var sign="";
		if(dn=="1"){
			sign="确实要禁用吗？";
		}else{
			sign="确实要启用吗？";
		}
		if(confirm(sign)){
			$.post("${ctx}/topic/topic-disableorenable.action?topic.topicId="+id+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("成功");
				}else{
					alert("失败");
				}		}); 
		}
	}
	//是否审核该专题下的文章
	function auditOrNo(id,dn){
		var myDate=new Date();
		var sign="";
		if(dn=="1"){
			sign="确实不要审核吗？";
		}else{
			sign="确实要审核吗？";
		}
		if(confirm(sign)){
			$.post("${ctx}/topic/topic-auditorno.action?topic.topicId="+id+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("成功");
				}else{
					alert("失败");
				}		}); 
		}
	}
	
	var g = function(D) {
		if ( D.indexOf(" ") == -1){
			return ( D.substring(0,1) === "#") ? document.getElementById(D.substring(1,D.length)) : document.getElementsByTagName(D);
		}
		else {
			var ary = D.split(" ");
			return g(ary[0]).getElementsByTagName(ary[1]);
		}
	};
	function inputvalue(){
		var d = g("#listbox input"), i = 0, j = d.length, str = "";
	    for ( ; i < j ; i ++ ) {
				str += (d[i].type == "checkbox" && d[i].id != "totalCheck" && d[i].checked == true ) ? d[i].value + "@" : "";
		};	
		return (str.slice(0,-1));
	};
	
	//批量禁用
	function batchDisable(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("您未选择任何一个");
			return; 
		}
		if(!ids){
			alert("您未选择任何一个");
			return;		
		}
		var myDate=new Date();
		if(confirm("确实要禁用吗？")){
			$.post("${ctx}/topic/topic-batchdisable.action?ids="+ids+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("禁用成功");
				}else if(data=="sorroy"){
					alert("您没有权限");
				}else{
					alert("禁用失败");
				}		
			});
		}
	}
	//批量启用
	function batchEnable(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("您未选择任何一个");
			return; 
		}
		if(!ids){
			alert("您未选择任何一个");
			return;		
		}
		var myDate=new Date();
		if(confirm("确实要启用吗？")){
			$.post("${ctx}/topic/topic-batchenable.action?ids="+ids+"&myTime="+myDate,function(data){
				if(data=="ok"){
					window.location.reload(); 
					alert("启用成功");
				}else if(data=="sorroy"){
					alert("您没有权限");
				}else{
					alert("启用失败");
				}		
			});
		}
		 
	}
	
	//批量删除
	function goBatchDel(){
		var ids = inputvalue();
		if(ids=="on"){
			alert("您未选择任何一个");
			return; 
		}
		if(!ids){
			alert("您未选择任何一个");
			return;
		}
		if(confirm("确实要删除吗?")){
			$.post("${ctx}/topic/topic-delete.action?ids="+ids,
					  function(data){
							message=data+"";
							if(data=="sorroy"){
								alert("您没有权限");
							}else if(data=="yes"){
								alert("删除成功!");
							}else{
								alert("专题:"+data+"有内容不能删除!");
							}
							window.location.reload();	
					});
		}
	}
	
	//批量审核
	 function batchAudit(){
		 var ids = inputvalue();
		    if(ids=="on"){
				alert("您未选择任何一个");
				return; 
			}
			if(!ids){
				alert("您未选择任何一个");
				return;		
			}
			var myDate=new Date();
			if(confirm("确实需要审核吗？")){
				$.post("${ctx}/topic/topic-batchaudit.action?ids="+ids+"&myTime="+myDate,function(data){
					if(data=="ok"){
						window.location.reload(); 
						alert("设置成功");
					}else if(data="sorroy"){
						alert("您没有权限");
					}else{
						alert("设置失败");
					}		
				});
			}
	}
	
	//批量不审核
	 function batchNoAudit(){
		 var ids = inputvalue();
		 if(ids=="on"){
				alert("您未选择任何一个");
				return; 
			}
			if(!ids){
				alert("您未选择任何一个");
				return;		
			}
			var myDate=new Date();
			if(confirm("确实不需要审核吗？")){
				$.post("${ctx}/topic/topic-batchnoaudit.action?ids="+ids+"&myTime="+myDate,function(data){
					if(data=="ok"){
						window.location.reload(); 
						alert("设置成功");
					}else if(data="sorroy"){
						alert("您没有权限");
					}else{
						alert("设置失败");
					}		});
			}
	}
	
	//审核人设置-选择审核人
	function authorSelect(tipicId,auditNasmes){
		$.getJSON("${ctx}/topic/topic-authorsetselect.action",function(data){
			var htmlStr = "";
			var authorArray = new Array(data.length);
			for(var i=0;i<data.length;i++){
				var adminId = data[i].adminId;
				var loginName = data[i].loginName;
				var realName=data[i].realName;
				if(realName==null){
					authorArray[i]="<li><input name=\"autor\" type='checkbox' onclick=\"addAuthor('"+tipicId+"')\" value='"+loginName+"'>&nbsp;"+loginName+"</li>";
				}else{
					authorArray[i]="<li><input name=\"autor\" type='checkbox' onclick=\"addAuthor('"+tipicId+"')\" value='"+loginName+"'>&nbsp;"+loginName+"&nbsp;&nbsp;<a id='realName"+i+"'>"+realName+"</a></li>";
				}
			}
			htmlStr = authorArray.join("");
			$("#authorSetDiv").html(htmlStr);
			reshowAuditNasmes(auditNasmes);
		});
	}
	//审核人回显
	function  reshowAuditNasmes(auditNasmes){
		if(!auditNasmes || $.trim(auditNasmes)=='')  return;
		var auth = auditNasmes.split(",");
		$("#authorSetDiv").find("input:checkbox[name='autor']").each(function(){
			var v = $(this).val();
			for(var j=0;j<auth.length;j++){
				if(v == auth[j]) $(this).attr("checked",true);
			}
		});
		
	}
	 
	
	
	function addAuthor(topicId){
		$("#topicId").val(topicId);
	}
	var batch = "";
	//审核人设置-保存审核人到数据库
	function authorSet(){
		 var ids = inputvalue();
		 var topicId = $("#topicId").val();
		 var ids = inputvalue();
		 var arr = new Array();
			$("#authorSetDiv").find('input:checkbox[name="autor"]:checked').each(function(i,item){
				 var s = $(item).val();
				 arr.push(s);
			});
		    var  str = arr.join(',');
		    if( batch == "batchs"){
		    	$.get("${ctx}/topic/topic-authorset.action?ids="+ids+"&adminName="+str,function(data){
					if(data == "ok"){
						alert("设置审核人成功");
			  			window.location.reload(); 
					}
				}); 
		    }else{
		    	$.get("${ctx}/topic/topic-authorset.action?topic.topicId="+topicId+"&adminName="+str,function(data){
					if(data == "ok"){
						alert("设置审核人成功");
			  			window.location.reload(); 
					}
				}); 
		    }
		    
	}
	//批量审核人设置
	function batchAuthorSet(){
		    var ids = inputvalue();
		    var myDate = new Date();
			if(!ids){
				alert("您未选择任何一个");
				return;		
			}
		   $.post("${ctx}/topic/topic-authorset.action?ids="+ids+"&myTime="+myDate,function(data){				
				if(data=="sorroy"){
					alert("您没有权限");
				} else{
					 authorSelect();
					 batch = "batchs";
				}
			});
		
	}
	
	//审核
	function goAudit(id){
		document.location.href="topic-input.action?topic.topicId="+id+"&orig=audit";
	}
	
	
	
	var keywords = $("#keywords").val();
	
	//专题下的内容管理
	function goManage(topicId){
		window.open("${ctx}/content/content-list.action?topic.topicId="+topicId+"&tflag=1",'olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes');
	}
	//删除单个专题
	function goDeltest(id){
		var topicid=id;
		if(confirm("确实要删除吗？")){
			$.post("${ctx}/topic/topic-delete.action?key="+topicid,
					  function(data){
							if(data=="no"){
								alert("专题下有内容不能删除！");
							}
							window.location.reload(); 
						});
		     }	
	 }
	$(function(){
		if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
			$('#main_box').width($('#main_box').width()-25);
		}
	});

	//动态预览
	function goDynamicPreview(topicId){
		var url = "${ctx}/generate/preview.action?targets="+topicId+"&type=topic"; 
		window.open(url,'olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes'); 
	}
	//静态预览
	function goStaticPreview(topicId){
		$.post("${ctx}/topic/topic-getsimplename.action?category.categoryId="+topicId,function(data){
			var json = eval('('+data+')');
			if(json.flag){
				window.open(json.url,'olcwhatispaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes');
			}else{
				alert("专题未发布，无法进行静态预览!");
			}
		});
	}
	//发布
	function goPublish(){
		alert("对不起，暂时还不能发布");
	}
	</script>
